/**
 * (C)2013 Exlu Corporation. All rights reserved.
 * 文件名 : cn.exlu.wea.tpk.test.SendHtmlMessage.java
 * 注意事項   :
 */
package cn.exlu.wea.tpk.test;

import java.io.IOException;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import cn.exlu.wea.tpk.email.LoginAuthentication;

/**
 * @author Mark 
 * @version 1.0.1
 * 2013-1-31
 * SendHtmlMessage.java
 */
public class SendHtmlMessage {

    /**
     * @param args
     * @throws MessagingException 
     * @throws AddressException 
     * @throws IOException 
     */
    public static void main(String[] args) throws AddressException, MessagingException, IOException {
        Properties prop=new Properties();
        prop.put("mail.smtp.host", "smtp.126.com");
        prop.put("mail.smtp.auth", true);
        
        LoginAuthentication loginAuth=new LoginAuthentication("testlogin123@126.com","testlogin");
        Session session=Session.getDefaultInstance(prop, loginAuth);
        
        Message message=new MimeMessage(session);
        message.setFrom(new InternetAddress("testlogin123@126.com"));
        message.addRecipient(Message.RecipientType.TO, new InternetAddress("sendMark@126.com"));
        message.setSubject("send a attachment to you");
        String htmlText="<H1>Hello</H1>";
        FileStringReader fr=new FileStringReader("D:/apppender1.log","utf8");
        StringBuffer sb=new StringBuffer();
        String msg="";
        while((msg=fr.readLine())!=null){
            sb.append(msg);
        }
        System.out.println(sb.toString());
        
        message.setContent(sb.toString(), "text/html;charset=gb2312");
        Transport.send(message);
        
        

    }

}
